package cn.edu.nju.ws.sview.rdf;

/**
 * plain literal
 * 
 * @author Gong Saisai
 * 
 */
public class PlainLiteral extends Literal {
	private String languageTag = null;

	/**
	 * 
	 * @param lexicalForm ��literal�ַ���ʽ
	 * @param languageTag ��literal���Ա�ǩ
	 */
	PlainLiteral(String lexicalForm, String languageTag) {
		super(lexicalForm);
		this.languageTag = languageTag;
	}

	/**
	 * 
	 * @return ��literal��language tag������Ϊnull
	 */
	public String getLanguageTag() {
		return this.languageTag;
	}

	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result =1 ;
		result = prime * result+this.lexicalForm.hashCode();
		result = prime * result
				+ ((languageTag == null) ? 0 : languageTag.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
	    if(obj instanceof PlainLiteral){
	    	PlainLiteral pliteral = (PlainLiteral)obj;
	    	if(this.lexicalForm.equals(pliteral.getLexicalForm())){
	    		if(this.languageTag==null){
	    			if(pliteral.languageTag==null)
	    				return true;
	    		}else if(this.languageTag.equals(pliteral.getLanguageTag()))
	    			return true;
	    	}
	    }
		return false;
	}

	public String toString() {
		return "\""
				+ this.lexicalForm
				+ "\""
				+ ((this.languageTag==null || this.languageTag.equals("")) ? ""
						: ("@" + this.languageTag));
	}
}